package com.ruoyi.system.Controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CmCourtBlock;
import com.ruoyi.system.service.ICmCourtBlockService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单元信息Controller
 * 
 * @author pop404NotFound
 * @date 2021-11-24
 */
@Controller
@RequestMapping("/CmSystem/Courtblock")
public class CmCourtBlockController extends BaseController
{
    private String prefix = "CmSystem/Courtblock";

    @Autowired
    private ICmCourtBlockService cmCourtBlockService;

    @RequiresPermissions("CmSystem:Courtblock:view")
    @GetMapping()
    public String Courtblock()
    {
        return prefix + "/Courtblock";
    }

    /**
     * 查询单元信息列表
     */
    @RequiresPermissions("CmSystem:Courtblock:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmCourtBlock cmCourtBlock)
    {
        startPage();
        List<CmCourtBlock> list = cmCourtBlockService.selectCmCourtBlockList(cmCourtBlock);
        return getDataTable(list);
    }

    /**
     * 导出单元信息列表
     */
    @RequiresPermissions("CmSystem:Courtblock:export")
    @Log(title = "单元信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmCourtBlock cmCourtBlock)
    {
        List<CmCourtBlock> list = cmCourtBlockService.selectCmCourtBlockList(cmCourtBlock);
        ExcelUtil<CmCourtBlock> util = new ExcelUtil<CmCourtBlock>(CmCourtBlock.class);
        return util.exportExcel(list, "单元信息数据");
    }

    /**
     * 新增单元信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存单元信息
     */
    @RequiresPermissions("CmSystem:Courtblock:add")
    @Log(title = "单元信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmCourtBlock cmCourtBlock)
    {
        return toAjax(cmCourtBlockService.insertCmCourtBlock(cmCourtBlock));
    }

    /**
     * 修改单元信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmCourtBlock cmCourtBlock = cmCourtBlockService.selectCmCourtBlockById(id);
        mmap.put("cmCourtBlock", cmCourtBlock);
        return prefix + "/edit";
    }

    /**
     * 修改保存单元信息
     */
//    @RequiresPermissions("CmSystem:Courtblock:edit")
//    @Log(title = "单元信息", businessType = BusinessType.UPDATE)
//    @PostMapping("/edit")
//    @ResponseBody
//    public AjaxResult editSave(CmCourtBlock cmCourtBlock)
//    {
//        return toAjax(cmCourtBlockService.updateCmCourtBlock(cmCourtBlock));
//    }

    /**
     * 删除单元信息
     */
    @RequiresPermissions("CmSystem:Courtblock:remove")
    @Log(title = "单元信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmCourtBlockService.deleteCmCourtBlockByIds(ids));
    }

    /**
     *
     * 更改单元信息
     *
     */
    @GetMapping("/updateinfo/{id}")
    @ResponseBody
    public AjaxResult updateInfo(@PathVariable("id") Long id){
        return toAjax(cmCourtBlockService.updateCmUserInfo(id));
    }
}
